<template>
	<view>
				<image class="backimg" :src="baseUrl + '/static/icon/left_jt.png'" mode="aspectFill" @click="goBack">
		<image class="mm" src="https://images.fudiemall.com/storage/default/20250715/download150188420781e7e7aa7e1024b4a035fdaeddae02.png" mode="aspectFill"></image>
		<view class="btnwrap">
			<view class="btn2" @click="gosss()">
				打开福叠猫APP
			</view>
			<view class="btn2"  @click="gonext()" style="margin-top: 30rpx;background-color: #FF8B40;">
				下载福叠猫APP
			</view>
			<!-- <image src="https://images.fudiemall.com/storage/default/20250715/android7c719fb8751ecc82d61ddfc7eb2da1f5006559dc.png" mode="aspectFill"></image> -->
			<!-- <image style="margin-top: 50rpx;"  src="https://images.fudiemall.com/storage/default/20250715/ios71fcf01d1c2f31159acc31e45336d94449b2a3b6.png" mode="aspectFill"></image> -->
		</view>
	</view>
</template>

<script>
	import { appVersion } from "../../api/other.js"
	export default {
		data() {
			return {
				baseUrl: this.$imageBaseUrl,
				downloadUrl:""
			}
		},
		onLoad() {
			this.getinfo()
		},
		
		methods: {
			gonext(){
				window.location.href = this.downloadUrl;
			},
			getinfo(){
			 const app=	uni.getSystemInfoSync().osName
			 console.log(app)
				appVersion({
					type:app=='ios'?"2":"1"
				}).then(res=>{
					this.downloadUrl=res.data.download_url
				})
			},
			goBack() {
				const canNavBack = getCurrentPages()
				console.log(canNavBack.length);
				// 判断是否刷新了浏览器，刷新了浏览器，页面栈只有当前一个
				if (canNavBack.length > 1) {
					uni.navigateBack({
						delta: 1
					})
				} else {
					uni.switchTab({
						url: '/pages/index/cloudCatIndex'
					})
				}
			},
			gosss() {
			  const appScheme = 'fudiemall://com.fuhe.fudiemall';
			  const downloadUrl = this.downloadUrl; // 请替换为实际地址
			  
			  // 记录开始时间
			  const startTime = Date.now();
			  
			  // 尝试打开App
			  window.location.href = appScheme;
			  
			  // 设置检测定时器
			  const checkTimer = setInterval(() => {
			    // 如果页面隐藏了（说明成功跳转到App）
			    if (document.hidden) {
			      clearInterval(checkTimer);
			      console.log('检测到App已安装并已打开');
			      return;
			    }
			    
			    // 如果超过2秒页面仍然可见（假设未安装App）
			    if (Date.now() - startTime > 2000) {
			      clearInterval(checkTimer);
			      console.log('未检测到App，跳转到下载页');
			      window.location.href = downloadUrl;
			    }
			  }, 100);
			  
			  // 添加visibilitychange事件监听作为双重保障
			  const visibilityHandler = () => {
			    if (document.hidden) {
			      clearInterval(checkTimer);
			      document.removeEventListener('visibilitychange', visibilityHandler);
			    }
			  };
			  document.addEventListener('visibilitychange', visibilityHandler);
			},
		}
	}
</script>

<style lang="scss">
.mm{
	width: 750rpx;
	height: 1250rpx;
}
.btnwrap{
	width: 750rpx;
	height: 376rpx;
	display: flex;
	flex-direction: column;
	justify-content: center;
	align-items: center;
	

}

	.backimg {
		position: absolute;
		top: 8%;
		left: 20rpx;
		transform: translateY(-50%);
		width: 60rpx;
		height: 60rpx;
		z-index: 66;
	}
	.btn1{
		// margin-top: 20rpx;
		width: 640rpx;
		height: 80rpx;
		background: #FFAD04;
		line-height: 80rpx;
		text-align: center;
		color: #fff;
		font-size: 32rpx;
	}
.btn2{
	width: 640rpx;
	height: 80rpx;
	background: #FFAD04;
	line-height: 80rpx;
	text-align: center;
	color: #fff;
	font-size: 32rpx;
	border-radius: 20rpx;
}
</style>
